//
//  ByViewDayEarningHeader.m
//  mijifen_ios
//
//  Created by mc on 2017/10/26.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByViewDayEarningHeader.h"


// vc
#import "ByDayEarningApplyVC.h"
#import "ByDayEarningPointSwitch.h"
// view
#import "ByViewDayEarningPointSwitch.h"

@implementation ByViewDayEarningHeader
- (instancetype)init{
    if (self = [super init]) {
        [self createViews];
        self.backgroundColor = BY_THEME_COLOR;
    }
    return self;
}

- (void)createViews{
    NSArray *titleAry = @[@"账户余额：",@"已收积分："];
    NSArray *subAry = @[@"申请提现",@"积分转换"];
    // 测试数据
    NSArray *testArray = @[@"¥26666.56",@"90900"];
    CGFloat title_margin = 20;
    for (int i = 0; i < titleAry.count; i ++) {
        UILabel *titleLabel = [[UILabel alloc] init];
        [self addSubview:titleLabel];
        CGFloat width = [titleAry[i] getSizeOfString:18].width + 5;
        CGFloat y;
        if (i == 0) {
            y = title_margin;
        }else{
            y = title_margin * 3 + 20;
        }
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left).offset(10);
            make.top.equalTo(self.mas_top).offset(y);
            make.size.mas_equalTo(CGSizeMake(width, 20));
        }];
        titleLabel.textColor = [UIColor darkGrayColor];
        titleLabel.font = FONT(18);
        titleLabel.text = titleAry[i];
        
        UIButton *eventButton = [[UIButton alloc] init];
        [self addSubview:eventButton];
        [eventButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_right).offset(-10);
            make.top.equalTo(self.mas_top).offset(y);
            make.size.mas_equalTo(CGSizeMake(width, 20));
        }];
        [eventButton setTitle:subAry[i] forState:UIControlStateNormal];
        [eventButton setTitleColor:BY_TEXT_COLOR forState:UIControlStateNormal];
        eventButton.titleLabel.font = FONT(18);
        [eventButton addTarget:self action:@selector(eventAction:) forControlEvents:UIControlEventTouchUpInside];

        UILabel *infoLabel = [[UILabel alloc] init];
        [self addSubview:infoLabel];
        [infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(titleLabel.mas_right);
            make.bottom.equalTo(titleLabel.mas_bottom);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 20 - width * 2, 30));
        }];
        infoLabel.tag = 10 + i;
        infoLabel.textColor = [UIColor whiteColor];
        infoLabel.font = FONT(30);
        infoLabel.adjustsFontSizeToFitWidth = YES;
        
        if (i == 0) {
            UIView *lineView = [[UIView alloc] init];
            [self addSubview:lineView];
            [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.mas_left).offset(10);
                make.top.equalTo(self.mas_top).offset(60);
                make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 20, 1));
            }];
            lineView.backgroundColor = [UIColor darkGrayColor];
        }
        
        infoLabel.text = testArray[i];
        
        
    }
}

- (void)eventAction:(UIButton *)button{
    if ([button.titleLabel.text isEqualToString:@"申请提现"]) {
        ByDayEarningApplyVC *vc = [[ByDayEarningApplyVC alloc] init];
        [(ByBaseVC *)self.viewController by_normalPush:vc hasNavi:YES];
    }else{
        ByViewDayEarningPointSwitch *view = [[ByViewDayEarningPointSwitch alloc] init];
        view.point = @"3000";
        __weak typeof(view) weakView = view;
        view.sureBlock = ^{
            ByDayEarningPointSwitch *vc = [[ByDayEarningPointSwitch alloc] init];
            vc.point = weakView.point;
            [(ByBaseVC *)self.viewController by_normalPush:vc hasNavi:YES];
            [weakView remove];
        };
        [view show];
    }
}



@end
